package com.bnz.controller;

import com.bnz.pojo.PageResult;
import com.bnz.pojo.R;
import com.bnz.pojo.Student;
import com.bnz.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private IStudentService studentService;


    //1. 查询所有学生
    @GetMapping("/list")
    public R list(){
        //1.1 查询所有学生
        List<Student> students = studentService.list();
        return R.ok().data("students",students);
    }

    //2. 分页查询
    @GetMapping("/findByPage")
    public R findByPage(){
        //2.1 开始分页
        int page = 1;
        int pageSize = 3;
        //2.2 开始分页查询
        PageResult<Student> pr = studentService.findByPage(page, pageSize);
        //2.3 返回
        return R.ok().data("pr",pr);
    }
}
